package com.csdj.game.interceptors;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 检验用户登录状
 * 当session 中存在 username 这个属性则认为用户已经登录
 * author:cloud
 * date:2021/3/30 0030
 **/
public class LoginIntercetpor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String username = (String)request.getSession().getAttribute("username");
        if(username == null || "".equals(username)){
            //没有登录

            response.sendRedirect(request.getContextPath()+"/user/login");
            return false;
        }
        return true;
    }
}
